package com.yb.xczx.security.resource.config;

import com.yb.core.enums.HttpCode;
import com.yb.core.model.XczxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/5/19 18:52
 * FileName: SecurityExceptionHandler
 * Description:
 */
@RestControllerAdvice
@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE+1)
public class SecurityExceptionHandler {

    @ExceptionHandler(AccessDeniedException.class)
    public XczxResult handle(AccessDeniedException ex){
        log.error(String.format("错误信息:%s",ex.getMessage()), ex);
        return  XczxResult.error(HttpCode.Response.FORBIDDEN);
    }
}
